# -*- coding: utf-8 -*-
# copyright 2009  Nik Lutz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.kdeui import *
from PyKDE4.kio import *
from PyKDE4.kdecore import *
from ui_miscparameters import Ui_Form

class MiscParameters(QWidget, Ui_Form):
    
    notification_values = ["Persistent", "CloseOnTimeout", "CloseWhenWidgetActivated", "None" ]
    misc_values = ["drawbackground", "showlabel" , "debugoutput", "showservicessearchfield" ]
    def __init__(self, configuration ):
        QWidget.__init__(self)

        self.setupUi(self)
        
        for config in self.misc_values :
            self.__dict__[config].setChecked(self.parseBoolString(configuration[config]))
        
        for value in self.notification_values :
            self.notificationtype.addItem(value)
        self.notificationtype.setCurrentIndex(self.notification_values.index(configuration["notificationtype"]))
        
        self.backgroundcolor.setColor(QColor(configuration["backgroundcolor"]))

        
    
    def applyConfiguration(self, aDict):
        for config in self.misc_values:
            aDict[config] = str(self.__dict__[config].isChecked())
        aDict["backgroundcolor"] = self.backgroundcolor.color().name()
        aDict["notificationtype"] = self.notification_values[self.notificationtype.currentIndex()]
        

    def parseBoolString(self,boolOrString):
        if boolOrString is True or boolOrString is False:
            return boolOrString
        return boolOrString[0].upper()=="T"



